package com.server.runtime;

import java.io.Serializable;

import com.server.core.Simulator;

import combat.protocol.data.DoublePoint;
import combat.protocol.interfaces.PhysicalObjectInt;
import combat.protocol.types.PhysicalObjectType;

public class PhysicalObject implements PhysicalObjectInt, Serializable {
	private static final long serialVersionUID = 1L;
	
	public PhysicalObjectType POType;
	public String name;
	public DoublePoint position;
	public int altitude;
	public double direction;
	public double speed;

	public PhysicalObject(String name, DoublePoint position, int altitude,
            double direction, double speed, PhysicalObjectType type) {
		this.name = name;
		this.position = position;
		this.altitude = altitude;
		this.direction = direction;
		this.speed = speed;
		this.POType = type;
	}

	public PhysicalObjectType getType() {
		return this.POType;
	}

	public void setType(PhysicalObjectType phyObjType) {
		this.POType = phyObjType;
	}

	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public DoublePoint getPosition() {
		return this.position;
	}

	public void setPosition(DoublePoint position) {
		this.position = position;
	}

	public int getAltitude() {
		return this.altitude;
	}

	public void setAltitude(int altitude) {
		this.altitude = altitude;
	}

	public double getDirection() {
		return this.direction;
	}

	public void setDirection(double direction) {
		this.direction = direction;
	}

	public double getSpeed() {
		return this.speed;
	}
	
	public void setSpeed(double speed) {
		this.speed = speed;
	}
	
	public static DoublePoint ToDoublePoint(Object _o)
	{
		DoublePoint _loc = new DoublePoint();

		if(_o.getClass().getSuperclass().equals(PhysicalObject.class)) {
		        PhysicalObject physobj = (PhysicalObject) _o;
		        _loc = physobj.getPosition();
		} else {
				_loc = (DoublePoint) _o;
		}
		
		return _loc;
	}
	
	//------------------------------
	
	public void calculateMovement()					
	{
		double multiplier = simulationImpl.getReference().getSimSpeed();
		if(multiplier == 0) {
			return;
		}
		
		double tempSpeed = (this.getSpeed()*multiplier)/Simulator.FRAME_SPLITTER; //multiplier is the game speed, FRAME_SPLITTER is a fine tune variable for changing the amount of frames per second(which will also affect the speed objects move)
		
		this.getPosition().setX(this.getPosition().getX() + tempSpeed * Math.cos((this.getDirection()/180)*Math.PI));
		this.getPosition().setY(this.getPosition().getY() + tempSpeed * Math.sin((this.getDirection()/180)*Math.PI));
		
	}
}
